# -*- coding = utf-8 -*-
# @Time : 2022/2/21 10:10
# @File : multithreading.py
# @Software : PyCharm

import time
from threading import Thread

table = 0
m = time.time()
zcount = 0
egg = 5


class Cook(Thread):
    name = ""
    money = 0
    tart = 0

    def run(self) -> None:
        global table
        global m
        while True:
            m1 = time.time()
            if m1 - m <= 5:
                self.tart = self.tart + 1
                table = table + 1
                if table % 20 == 0:
                    time.sleep(2)
                print(f"{self.name}做了1个蛋挞，桌子上共有{table}个蛋挞")
            else:
                tartmoney = self.tart * egg
                self.money = tartmoney * 0.7
                print(f"{self.name}做了{self.tart}个蛋挞他工资为{self.money}元")
                break


class Person(Thread):
    name = ''
    money = 0
    time = 0

    def run(self) -> None:
        global table
        global zcount
        while True:
            if table > 0:
                time.sleep(self.time)
                table = table - 1
                zcount = zcount + 1
                self.money = self.money - (zcount * 5)
                print(f"客户{self.name}抢购了{zcount}个蛋挞还剩{self.money}元")
                if self.money == 0:
                    print("钱花完了！")
                    break
            else:
                print(f"客户{self.name}一共抢购了{zcount}个蛋挞")
                print("店里的蛋挞卖完了！")
                break


class Store:
    store = 0

    def yingli(self):
        global table
        self.store = table * 5
        print('今天店里营业额为%s' % self.store)


# 厨师
cook1 = Cook()
cook2 = Cook()
cook3 = Cook()
cook1.name = "康师傅"
cook2.name = "赵师傅"
cook3.name = "张师傅"
cook1.start()
cook2.start()
cook3.start()

# 用户
p1 = Person()
p2 = Person()
p3 = Person()
p4 = Person()
p5 = Person()
p6 = Person()
p1.name = "张三"
p2.name = "李四"
p3.name = "王五"
p1.name = "赵六"
p2.name = "小红"
p3.name = "小夫"
p1.money = 30000
p2.money = 30000
p3.money = 30000
p4.money = 30000
p5.money = 30000
p6.money = 30000
p1.time = 0.5
p2.time = 0.6
p3.time = 0.5
p4.time = 0.6
p5.time = 0.5
p6.time = 0.4
p1.start()
p2.start()
p3.start()
p4.start()
p5.start()
p6.start()

# 盈利
money = Store()
print(money.yingli)
